package frontend.symtable.symbol;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 变量符号
 *
 * @author 杨凯伟
 * @date 2024/10/16
 */
public class VarSymbol extends Symbol {
    public Type varType = new Type();//int char
    public boolean isConst = false;//是否常量
    public final List<Integer> values = new ArrayList<>();//int变量的值

    public VarSymbol() {
    }

    public VarSymbol(String ident, boolean isConst) {
        this.ident = ident;
        this.isConst = isConst;
    }

    public boolean isArray() {
        return !varType.dims.isEmpty();
    }

    public String getIdentType() {
        StringBuilder type = new StringBuilder();
        if (isConst) {
            type.append("Const");
        }

        if (Objects.equals(varType.type, "INTTK")) {
            type.append("Int");
        } else {
            type.append("Char");
        }

        if (this.isArray()) {
            type.append("Array");
        }
        return type.toString();
    }

}
